/**
 * 将 ISO 时间格式（如 2025-10-29T09:09:57）转换为 YYYY-MM-DD HH:mm:ss
 * @param isoString - 时间字符串，支持 null/undefined
 * @returns 格式化后的时间或“未预约”
 */
export function formatDateTime(isoString: string | null | undefined): string {
  if (!isoString) return '未预约'

  try {
    const date = new Date(isoString)
    if (isNaN(date.getTime())) return '未预约'

    const year = date.getFullYear()
    const month = String(date.getMonth() + 1).padStart(2, '0')
    const day = String(date.getDate()).padStart(2, '0')
    const hours = String(date.getHours()).padStart(2, '0')
    const minutes = String(date.getMinutes()).padStart(2, '0')
    const seconds = String(date.getSeconds()).padStart(2, '0')

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  } catch (err) {
    console.error('时间格式化失败:', isoString, err)
    return '未预约'
  }
}